package com.yipinhouse.backstage.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.backstage.client.EstateWebQueryClient;
import com.yipinhouse.backstage.client.param.EsSearchEstateWebParam;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.house.client.EstateQueryClient;
import com.yipinhouse.house.client.param.EsSearchEstateParam;
import com.yipinhouse.house.client.result.EstateResultInfo;
import com.yipinhouse.house.client.result.PageEstateResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("backstage")
public class EstateWebQueryApiImpl implements EstateWebQueryClient {

    @Resource
    private EstateQueryClient estateQueryClient;

    /**
     * 查询小区
     *
     * @param esSearchEstateParam
     * @return
     */
    @Override
    public Result<PageEstateResultInfo> esSearchEstate(EsSearchEstateWebParam esSearchEstateParam) {
        log.info("查询小区：{}", esSearchEstateParam);
        EsSearchEstateParam esSearchEstateParam1 = BeanUtil.copyProperties(esSearchEstateParam, EsSearchEstateParam.class);
        Result result = estateQueryClient.esSearchEstate(esSearchEstateParam1);
        PageEstateResultInfo pageEstateResultInfo = BeanUtil.copyProperties(result.getData(), PageEstateResultInfo.class);
        return Result.getInstance(PageEstateResultInfo.class).setData(pageEstateResultInfo);
    }

    /**
     * 根据Id查询小区详情
     *
     * @param estateId
     * @return
     */
    @Override
    public Result<EstateResultInfo> checkEstate(Integer estateId) {
        Result<EstateResultInfo> estateResultInfoResult = estateQueryClient.checkEstate(estateId);
        EstateResultInfo resultInfoResultData = estateResultInfoResult.getData();
        return Result.getInstance(EstateResultInfo.class).setData(resultInfoResultData);
    }
}
